package com.carleasoft.mps.adu.business.org.controller;


import com.carleasoft.mps.adu.business.org.bean.entity.OrganizationType;
import com.carleasoft.mps.adu.business.org.bean.po.OrgTypePo;
import com.carleasoft.mps.adu.business.org.service.OrganizationTypeService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.SortPo;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 组织分类表 前端控制器
 * </p>
 *
 * @author ztm
 * @since 2021-09-07
 */
@RestController
@RequestMapping("/organizationType")
public class OrganizationTypeController {

    @Autowired
    private OrganizationTypeService organizationTypeService;

    @PostMapping("/add")
    public R addOrganizationType(@RequestBody OrganizationType organizationType){
        IBeanUtil.paramVerify(organizationType, "orgTypeName");
       return R.result(organizationTypeService.addOrganizationType(organizationType));
    }

    @PostMapping("/update")
    public R updateOrganizationType(@RequestBody OrgTypePo orgTypePo){
        IBeanUtil.paramVerify(orgTypePo, "orgTypeCode");
        return R.result(organizationTypeService.updateOrganizationType(orgTypePo));
    }

    @PostMapping("/delete")
    public R deleteOrganizationType(@RequestBody OrgTypePo orgTypePo){
        IBeanUtil.paramVerify(orgTypePo, "orgTypeCode");
        return R.result(organizationTypeService.deleteOrganizationType(orgTypePo));
    }
    /**
     * 排序
     * @param sortPo
     * @return
     */
    @PostMapping("/updateSort")
    public R updateSort(@RequestBody SortPo sortPo){
        IBeanUtil.paramVerify(sortPo, "code");
        return R.result(organizationTypeService.updateSort(sortPo));
    }

    @PostMapping("/tree")
    public R pageQuery(@RequestBody OrgTypePo orgTypePo){
        return R.ok(organizationTypeService.queryOrganizationType(orgTypePo));
    }

}
